Threads

Back to se350

Relationship with Processes

Processes own resources, so processes include a virtual address space to hold the process image

Processes have to be scheduled and execute, and may be interleaved with other processes.

We use threads to execute within a process and use the resources of a process.

Benefits of Threads

Behaviour

User-level threads

Kernel-level threads

Microkernels

Concurrency

Requirements

Terms

OS Concerns

Interaction among processes

  1. Processes are unwaware of each other
  2. Processes are indirectly aware of each other
  3. Processes are directly aware of each other

Mechanisms for mutual exclusion

Advanced mechanisms

Semaphores

A concurrency control mechanism based on special variable for signalling. If a process is waiting for a signal, it is suspended until the signal is sent.

Monitors

Mesa monitors

Message passing

Reader/Writer Problem

Deadlock

Resources

Reusable

Consumable

Conditions for Deadlock

Avoidance at runtime

e.g.

  1. Do not start a process if its demands might deadlock
  2. Do not grant incremental resource request if this might lead to deadlock

Referred to as the Banker's Algorithm. The state of the system is the current allocation of resources to process. It is in a safe state if there is at least one sequence that doesn't result in deadlock. The goal is to always have a safe state.

Conditions and requirements:

Recovering

Unix concurrency